/*
包含多个基于state的getter计算属性的对象
 */
export default {
  // 当前的site
  currentSite: state => {
    return state.site
  },
  currentSiteConfig: state => {
    return state.site.config
  },
  // 所有的语言数据
  alllanguage: state => {
    return state.alllanguage
  },
  // 当前的菜单信息
  currentMenu: state => {
    return state.menu
  },
  // 当前的导航信息
  currentNav: state => {
    return state.nav
  },
  // 当前的角色权限是否具有
  currentRoles: state => {
    let guest = false
    let user = false
    let edit = false
    let design = false
    let roles = state.user.roles
    if (roles) {
      for (let i in roles) {
        let role = roles[i]
        if (role.role === 'guest') {
          guest = true
        }
        if (role.role === 'user') {
          user = true
        }
        if (role.role === 'edit') {
          edit = true
        }
        if (role.role === 'design') {
          design = true
        }
      }
    }
    return { guest, user, edit, design }
  },
  // 是否是试用
  trial: state => {
    return state.host.trial > 0
  },
  /**
   * 是否是正式站点或者设计师登录用户
   *  */
  sudo: state => {
    if (state.host.trial > 0) {
      return true
    }
    if (state.user.loginUserType === 'designUser') {
      return true
    }
    return false
  },
  // 获取iframe的 src 路径
  currentIframeSrc: state => {
    if (state.design && state.design.iframeSrc) {
      return state.design.iframeSrc
    }
    return false
  },
  // 获取设计区域渲染完成后的 pageId
  currentPageId: state => {
    if (state.design) {
      return state.design.pageId
    }
    return false
  }
}
